package com.wedo.mall.activity.user;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.http.EClient;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;
import com.wedo.mall.R;
import com.wedo.mall.entity.MessageItem;
import com.wedo.mall.util.DateUtils;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observable;

public class FeedbackActivity extends EActivity {

    @BindView(R.id.et_content) EditText et_content;

    @Override
    protected int layout() {
        return R.layout.activity_feedback;
    }

    @Override
    protected void onActivityCreated(Bundle state) {

    }


    private void postFeedback(){
        this.loading();
        Map<String,String> params = new HashMap<>(1);
        params.put("text",et_content.getText().toString());
        Observable<EResponse> observable = EClient.with().api().post(EApi.USER_FEEDBACK,params);
        EClient.with().observer(observable, new EObserver() {
            @Override
            public void successful(EResponse response) {
                toast(getString(R.string.postsuccessful));
                FeedbackActivity.this.dismiss();
                finish();
            }

            @Override
            public void failure(String msg) {
                FeedbackActivity.this.dismiss(msg);
            }
        });
    }

    @OnClick(R.id.btn_submit)
    protected void onFeedbackClick(){
        if(et_content.getText().toString() == ""){
            toast(getString(R.string.user_unnull));
        }else{
            postFeedback();
        }
    }
}
